package org.glut.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@SpringBootApplication
public class MicroserviceGatewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(MicroserviceGatewayApplication.class, args);
    }
    @Bean
    public RedisTemplate redisStringTemplate(RedisTemplate<Object, Object> redisTemplate) {
        // log.info("\n configure redisStringTemplate bean \n");
        StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
        //缓存时 key 的序列化问题
        redisTemplate.setKeySerializer(stringRedisSerializer);
        //hash key序列化方式
        redisTemplate.setHashKeySerializer(stringRedisSerializer);

        // 如果手动将Value转换成了JSON，就不要再用JSON序列化器了。
        redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<>(Object.class));
        // redisTemplate.setValueSerializer(stringRedisSerializer);
        return redisTemplate;
    }

}
